package com.axt.dbaudit.unitTest;

import java.util.*;

import com.axt.soa.bean.BaseFuncBean;
import com.axt.util.DateTime;
import com.axt.util.TypeConvert;
import com.axt.dbaudit.base.QueryFilter;
import com.axt.dbaudit.base.QueryFilterType;
import com.axt.dbaudit.base.QueryType;
import com.axt.dbaudit.bean.query.QueryAlarmBean;
import com.axt.dbaudit.bean.query.QueryStmtBean;
import com.axt.dbaudit.model.*;
import com.axt.dbaudit.model.query.Alarm;
import com.axt.dbaudit.model.query.RealAlarm;
import com.axt.dbaudit.model.query.Stmt;

public class SoaQuery extends BaseFuncBean {
	private QueryStmtBean queryStmtBean = new QueryStmtBean();

	public void test() {

		queryIndex();

		int process = 0;
		do {
			process = queryProcess();

		} while (process != 100 || process != -1);

		if (process == 100)
			queryStmts();
	}

	/**
	 * query index
	 * */
	int queryIndex() {
		/* set query filter */
		List<QueryFilter> queryFilters = new ArrayList<QueryFilter>();
		QueryFilter filter = new QueryFilter();

		filter.setFilterLogic(0);
		filter.setFilterRelation(0);
		filter.setFilterType(QueryFilterType.QUERY_F_TIMERAN);

		String fiterValueString;
		long queryTimeEnd, queryTimeBegin;
		try {
			queryTimeEnd = DateTime.UnixTimestamp("2012-05-16 00:00:00");
			queryTimeBegin = DateTime.UnixTimestamp("2012-05-01 00:00:00");
		} catch (Exception e) {
			// TODO: handle exception
			queryTimeEnd = queryTimeBegin = 0;
		}
		fiterValueString = queryTimeBegin + "##" + queryTimeEnd;

		filter.setFilterValue(fiterValueString);

		queryFilters.add(filter);
		/* query */
		return queryStmtBean.queryStmtIndices("-10", queryFilters, 0, 100);
	}

	int queryProcess() {
		List<QueryFilter> queryFilters = new ArrayList<QueryFilter>();
		QueryFilter filter = new QueryFilter();

		filter.setFilterLogic(0);
		filter.setFilterRelation(0);
		filter.setFilterType(QueryFilterType.QUERY_F_TIMERAN);
		
		queryFilters.add(filter);

		queryStmtBean.queryProcess("-10", queryFilters);
		

		System.out.println("查询进度："+queryStmtBean.getQueryProgress()+
				" 正在查询：" + queryStmtBean.getQueryDate());
		
		return TypeConvert.toInteger(queryStmtBean.getQueryProgress());
	}

	int stopQuery() {
		return 0;
	}

	List<RealAlarm> queryRealAlarm() {
		return null;
	}

	List<Stmt> queryStmts() {
		/* set query filter */
		List<QueryFilter> queryFilters = new ArrayList<QueryFilter>();
		QueryFilter filter = new QueryFilter();

		filter.setFilterLogic(0);
		filter.setFilterRelation(0);
		filter.setFilterType(QueryFilterType.QUERY_F_TIMERAN);

		String fiterValueString;
		long queryTimeEnd, queryTimeBegin;
		try {
			queryTimeEnd = DateTime.UnixTimestamp("2012-05-16 00:00:00");
			queryTimeBegin = DateTime.UnixTimestamp("2012-05-01 00:00:00");
		} catch (Exception e) {
			// TODO: handle exception
			queryTimeEnd = queryTimeBegin = 0;
		}
		fiterValueString = queryTimeBegin + "##" + queryTimeEnd;

		filter.setFilterValue(fiterValueString);

		queryFilters.add(filter);
		
		queryStmtBean.queryStmts("-10", queryFilters);
		
		return queryStmtBean.getStmts();
	}

	public static void main(String[] args) throws Exception {
		new SoaQuery().test();
	}

}
